package cn.itcast.jdbc;

import java.sql.*;

public class jdbcDemo02 {
    public static void main(String[] args) throws SQLException {

        // 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb7_procedure", "root", "my123456");
        //执行SQL
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from itheima_goods");
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();
        //处理结果集
        while (resultSet.next()) {//获取每一行
            //获取每一列数据
            for (int i = 1;i<=columnCount;i++){
                System.out.print(resultSet.getObject(i) +"\t");
//               resultSet.getObject(i);
            }
            System.out.println();
//            int sid = resultSet.getInt(1);
//            String sname = resultSet.getString(2);
//            int age = resultSet.getInt(3);
//            System.out.println(sid + "\t" + sname + "\t" + age);
        }
        //关闭连接
        resultSet.close();
        statement.close();
        connection.close();

    }
}
